#include "excelutlstest.h"
ExcelUtlsTest::ExcelUtlsTest(QObject* parent)
	: QObject(parent)
{
}
ExcelUtlsTest::~ExcelUtlsTest()
{
}
void ExcelUtlsTest::initTestCase()
{
	qDebug() << "CLASS:PinyinConverter START";
}
void ExcelUtlsTest::tstExportXlsxStringList()
{
	QString path = "output.xlsx";
	QString sheetName = "Sheet1";
	QList<QStringList> data;
	data << (QStringList() << "Name" << "Age" << "Gender")
		 << (QStringList() << "Alice" << "23" << "Female")
		 << (QStringList() << "Bob" << "30" << "Male");
	bool res = utils.exportXlsx(data, path, sheetName);
	QVERIFY(res);
	QFile file(path);
	QVERIFY(file.exists());
	auto vertifyData = utils.fromXlsx(path, sheetName);
	for (int i = 0; i < vertifyData.size(); ++i)
	{
		for (int j = 0; j < vertifyData[i].size(); ++j)
		{
			QVERIFY(vertifyData[i][j] == data[i][j]);
		}
	}
	QVERIFY(vertifyData.size() > 0);
	QVERIFY(vertifyData.size() == data.size());
}
void ExcelUtlsTest::tstXlsxJson()
{
	QString path = "output1.xlsx";
	QString sheetName = "Sheet1";
	QString jsonStr = R"([
    {"name": "Alice", "age": "23", "city": "London"},
    {"name": "Bob", "age": "30", "city": "New York"},
    {"name": "Charlie", "age": "28", "city": "Paris"}
])";
	auto res = utils.exportXlsx(jsonStr,path,sheetName);
	QVERIFY(res);
	QFile file(path);
	QVERIFY(file.exists());
}
void ExcelUtlsTest::cleanupTestCase()
{
	qDebug() << "CLASS:PinyinConverter END";
}
QTEST_MAIN(ExcelUtlsTest);